{% extends 'layout/basic.html' %}
{% load static %}

{% block title %} 用户登录 {% endblock %}

{% block css %}
    <link rel="stylesheet" href="{% static 'css/account.css' %}">
    <style>
        .error-msg {
            color: red;
            position: absolute;
            font-size: 12px;
        }
    </style>
{% endblock %}

{% block content %}
    <div class="account">
        <div class="title">用户登录</div>
        <form id="smsForm" method="post" novalidate>
            {% csrf_token %}
            {% for item in form %}
                {% if item.name == 'code' %}
                    <div class="form-group">
                        <label for="{{ item.id_for_label }}">{{ item.label }}</label>
                        {#                        <div class="clearfix">#}
                        <div class="row">
                            <div class="col-xs-7">
                                {{ item }}
                                <span class="error-msg">{{ item.errors.0 }}</span>
                            </div>
                            <div class="col-xs-5">
                                {#                                <img src="{% url 'image_code' %}">#}
                                <img src="/image/code/" id="imageCode" title="点击更换图片">
                            </div>
                        </div>
                    </div>
                {% else %}
                    <div class="form-group">
                        <label for="{{ item.id_for_label }}">{{ item.label }}</label>
                        {{ item }}
                        <span class="error-msg">{{ item.errors.0 }}</span>
                    </div>
                {% endif %}
            {% endfor %}

            <div>
                <div style="float: right">
                    <a href="/login/sms/">短信验证码登录</a>
                </div>
            </div>

            <div class="row">
                <div class="col-xs-3">
                    <input id="btnSubmit" type="submit" class="btn btn-primary" value="登 录"/>
                </div>
            </div>
        </form>
    </div>
{% endblock %}

{% block js %}
    <script>
        $('#imageCode').click(function () {
            // 获取原来的地址
            var oldSrc = $(this).attr('src');
            // 在原来的地址上加上一个？ 就在发送一个请求
            $(this).attr('src', oldSrc + "?");
        })
    </script>

{% endblock %}